/*
	This script update the employee record that has employee.employee_parking_space=null and 
	assign the highest parking space + 1 to it.
	
	@autor Victor Regalado
	@date 04/15/2010
	@pre-cond db and the employee table exist,employee.employee_parking_space=null
	@pos-cond db employee.employee_parking_space=next highest number
*/

USE db;

CREATE TRIGGER assing_parking_space 
	ON employee AFTER INSERT 
	AS 
		BEGIN 
			DECLARE @newVal int
			SELECT @newVal=((SELECT MAX(emp_parking_space) FROM employee)+1 )
			UPDATE employee SET emp_parking_space=@newVal WHERE emp_parking_space IS NULL;
		END